Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications (Jason Arnold's Library) by Tim Roadley

Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications (Jason Arnold's Library) by Tim Roadley

Author:Tim Roadley
Language: eng
Format: epub
Publisher: Addison-Wesley Professional
Published: 2014-08-15T00:00:00+00:00


To deep copy objects, several methods from the previous chapter will be used. The deep copy process will rely on a unique attribute name being chosen for each entity upfront. This allows a uniqueness check to take place prior to an object being copied, which prevents duplicated data. The following shows the high-level process for performing a deep copy:

An instance of CoreDataImporter is created with an NSDictionary of entity names mapped to a unique attribute per entity.

An NSArray of entity names to copy is given to the CoreDataImporter instance, which it iterates through one by one, copying all objects for each entity as required. You only need to specify the entities you want copied. Related objects of entities earmarked for copy will be copied regardless, however.

If equivalent objects from the source context don’t already exist in the target context, new managed objects are inserted. New objects are given the attribute values of the source object.

If a source object has a relationship, it is walked to find the related object(s). Related object(s) are copied to the target context as required.

Once all objects involved in a relationship exist in the target context, the relationship itself is reformed from the copied object to the related copied object(s) as previously illustrated in Figure 9.2 and Figure 9.3.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.